package com.yhally.seata.storage.tcc;

import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;

/**
 * tcc 库存事务模型
 *
 * @author wangyu
 * @version 1.0
 * @date 2022/5/8 22:03
 */
@LocalTCC
public interface StorageTccAction {

    /**
     * <p>描述: 一阶段 扣减库存
     * <p>开发者: wangyu
     * <p>时间: 2022/5/8 22:07
     *
     * @param businessActionContext
     * @param productId
     * @param count
     * @return boolean
     */
    @TwoPhaseBusinessAction(name = "stockAction", commitMethod = "commit", rollbackMethod = "rollback")
    boolean decrease(BusinessActionContext businessActionContext,
                     @BusinessActionContextParameter(paramName = "productId") Long productId,
                     @BusinessActionContextParameter(paramName = "count") Integer count);

    /**
     * <p>描述: 二阶段 扣减库存提交
     * <p>开发者: wangyu
     * <p>时间: 2022/5/8 22:08
     *
     * @param businessActionContext
     * @return boolean
     */
    boolean commit(BusinessActionContext businessActionContext);

    /**
     * <p>描述: 二阶段 扣减库存回滚
     * <p>开发者: wangyu
     * <p>时间: 2022/5/8 22:08
     *
     * @param businessActionContext
     * @return boolean
     */
    boolean rollback(BusinessActionContext businessActionContext);
}
